<?php
namespace slinks\extensions\action\core;

use slinks\extensions\action\configuration\IActionMapping;
use slinks\core\HttpFoundation\IRequest;
use slinks\core\HttpFoundation\ParameterBag;

/**
 * Description of ActionContext
 *
 * @author navid
 */
class ActionContext implements IActionContext{
    
    private $actionMapping;
    
    private $request;
    
    private $valueStack;
    
    public function __construct(IActionMapping $actionMapping,IRequest $request) {
        $this->actionMapping = $actionMapping;
        $this->request = $request;
        
        // setup valuestack with values from request.
        $valueStack = new ParameterBag($request->getSession()->getAttributes());
        $valueStack->add($request->queryParameters()->all());
        $valueStack->add($request->postParameters()->all());
        $valueStack->add($request->attributes()->all());
        $valueStack->set('_request',$request);
        $valueStack->set('_session',$request->getSession());
        $this->valueStack = $valueStack;
    }
    
    /**
     * @return slinks\extensions\action\configuration\IActionMapping
     */
    public function getActionMapping() {
        return $this->actionMapping;
    }

    /**
     * @return \slinks\core\HttpFoundation\IRequest the request object.
     */
    public function getRequest() {
        return $this->request;
    }

    /**
     * The IActionContext parameters. 
     * This is used internally by the Slinks Action framework to hold internal parameters.
     */
    public function getValueStack() {
        return $this->valueStack;
    }

    public function getSession() {
        return $this->request->getSession();
    }
    
}
